#include <QCoreApplication>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
class OneHandSort
{
public:
    vector <int> sortShelf(vector <int> target);
    void moveSlot(vector<int> &i,int empty);
};
vector <int> OneHandSort::sortShelf(vector <int> target)
{
    int empty=0,maxDisorderPisiotn=0;
    vector<int> result;
    do
    {
        maxDisorderPisiotn=0;
        for(int i=0;i<(int)target.size();i++)
        {
            if (target[i]!=i)
                maxDisorderPisiotn=max(maxDisorderPisiotn,i);
        }
        if(maxDisorderPisiotn == 0) break;
        for(int i=0;i<(int)target.size();i++)
        {
            if (maxDisorderPisiotn==target[i])
            {
                empty=i;
                break;
            }
        }
        result.push_back(empty);
        while(empty!=maxDisorderPisiotn)
        {
            for(int i=0;i<=maxDisorderPisiotn;i++)
            {
                if(target[i]==empty)
                {
                target[empty]=target[i];
                empty=i;
                result.push_back(empty);
                break;
                }
            }
        }
        result.push_back(target.size());
        target[maxDisorderPisiotn]= maxDisorderPisiotn;
    }while(maxDisorderPisiotn!=0);
    return result;
}


int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);
    vector <int> target;
    target.push_back(0);
    target.push_back(1);
    target.push_back(2);
//    target.push_back(2);
    OneHandSort test;
    vector <int> ans;
    ans = test.sortShelf(target);
    for(vector<int>::iterator it =ans.begin();it!=ans.end();it++)
        cout<<*it;
    return a.exec();
}
